// pages/MyQRcode/MyQRcode.js
Page({

    /**
     * 页面的初始数据
     */
    data: {
        userInfo: {
            img_url: 'https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fsafe-img.xhscdn.com%2Fbw1%2F7f7fcc74-10f6-4fe8-a6d8-4fc63fe61394%3FimageView2%2F2%2Fw%2F1080%2Fformat%2Fjpg&refer=http%3A%2F%2Fsafe-img.xhscdn.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1697867495&t=be0170aabe4c00b58c69850687c46b6b',
            name: '李天仙',
            code: '/pages/image/erweima.png'
        }
    },
    // 保存到相册
    saveImage() {
        wx.getImageInfo({
            src: this.data.userInfo.code,
            success(res) {
                const { width, height } = res;
                wx.saveImageToPhotosAlbum({
                    filePath: res.path,
                    success() {
                        wx.showToast({
                            title: '保存成功',
                            icon: 'success',
                            duration: 2000
                        });
                    },
                    fail() {
                        wx.showToast({
                            title: '保存失败',
                            icon: 'none',
                            duration: 2000
                        });
                    }
                });
            },
            fail() {
                wx.showToast({
                    title: '获取图片信息失败',
                    icon: 'none',
                    duration: 2000
                });
            }
        });
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {

    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {
        let user_name = wx.getStorageSync('user_name');
        let avatar = wx.getStorageSync('avatar');
        let share_code = wx.getStorageSync('share_code');

        // img_url: 'https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fsafe-img.xhscdn.com%2Fbw1%2F7f7fcc74-10f6-4fe8-a6d8-4fc63fe61394%3FimageView2%2F2%2Fw%2F1080%2Fformat%2Fjpg&refer=http%3A%2F%2Fsafe-img.xhscdn.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=auto?sec=1697867495&t=be0170aabe4c00b58c69850687c46b6b',
        // name: '李天仙',
        // code: '/pages/image/erweima.png'
        this.setData({
            'userInfo.name':user_name,
            'userInfo.img_url':avatar,
            'userInfo.code':share_code,
        })
    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})